# Maintainer (Arch): Lukas Fleischer <lfleischer@archlinux.org>
# Maintainer (Arch): David Runge <dvzrv@archlinux.org>
# Contributor: Hilton Medeiros <medeiros.hilton@gmail.com>
# Contributor: Dave Reisner <d@falconindy.com>
# Maintainer: Sagar Acharya <sagar@hyperbola.info>

pkgname=libgit2
pkgver=1.1.1
pkgrel=1
epoch=1
pkgdesc='A linkable library for Git'
arch=('x86_64')
url="https://libgit2.github.com/"
depends=('glibc' 'http-parser' 'libressl' 'pcre' 'zlib')
makedepends=('cmake' 'libssh2' 'python' 'quilt')
provides=('libgit2.so')
license=('GPL-2')
source=("$pkgname-$pkgver.tar.gz::https://github.com/libgit2/libgit2/archive/v${pkgver}.tar.gz"
		"series"
		"disable-online-tests.patch"
		"enable-repro-builds.patch")
sha512sums=('287255c81e5baa04d8fbce95efca8174cb34da8025cab979445d41e8361955f1d8c582d7705666ae9fc03c5215fc4f4f57e51d73d14ca9b063ed94077f88e6bc'
			'7dc60904e1e4568ca3d531e5dd500302afa1c265903735059aa7b901b0845f1018172bc97d4245011bf01ead82a90cce087e5061b258b16dc8f78703e52f5d83'
			'4fccb4d2c3b065f827a2f90d5d8ba020aedc74e337e647d9d1d1a5f3678966dbe3040822af55695462190bc7711c445e81568049adefa3202ecf5eab0f66c194'
			'a2f9be302d320e9ae2e92ff91c5194c21f325a38751336e4a415946cc024b2882a391d3b8b013a545dcd0dafca1cdb3bbb0e7632e7ba57348ecdb285cc909d5e')

prepare() {
	cd "$pkgname-$pkgver"
	
	mkdir ./patches
  	cp ${srcdir}/series ./patches
  	cp ${srcdir}/*.patch ./patches

  	export QUILT_PATCHES=patches
  	export QUILT_REFRESH_ARGS='-p ab --no-timestamps --no-index'
 	export QUILT_DIFF_ARGS='--no-timestamps'

  	quilt push -av
}


build() {
  cd "$pkgname-$pkgver"
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE='None' \
        -DUSE_HTTP_PARSER=system \
        -DTHREADSAFE=ON \
        -Wno-dev \
        -B build \
        -S .
  make -C build VERBOSE=1
}

check() {
  cd "$pkgname-$pkgver"
  make -C build test VERBOSE=1
}

package() {
  depends+=('libssh2')
  cd "$pkgname-$pkgver"
  make -C build DESTDIR="$pkgdir" install
  install -vDm 644 {AUTHORS,README.md} -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm644 COPYING -t "$pkgdir"/usr/share/licenses/$pkgname/
}
